// MainMenuSubclass.h: interface for the CMainMenuSubclass class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MAINMENUSUBCLASS_H__381F2AC3_0C44_4BD3_A0C9_647DDB3980A7__INCLUDED_)
#define AFX_MAINMENUSUBCLASS_H__381F2AC3_0C44_4BD3_A0C9_647DDB3980A7__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define IS_NORMAL 0x0001
#define IS_FOCUS 0x0002
#define IS_PRESSED 0x0004


class CMainMenuSubclass;

class CMenuItem
{
// Construction
public:
	CMenuItem(CMenu* pMainMenu, int nIndex, CMainMenuSubclass* pMainMenuSubclass);
	virtual ~CMenuItem();

	void SetState(BYTE bNewState) { m_fsState = bNewState; }
	BYTE GetState() const { return m_fsState; }
	CRect GetRect() const { return m_rcItem; }

	void OnPaint(CDC*);
	void TrackPopup(CWnd* pMainWnd);

protected:
	BYTE m_fsState;    // menu item state
	CRect m_rcItem;    // current rect
	CMenu* m_pMenuSub;
	CString m_strCaption;

private:
	void SetOwnerDraw(CMenu* pMenu);
	void UnsetOwnerDraw(CMenu* pMenu);
};

class CMainMenuSubclass  
{
public:
	CMainMenuSubclass();
	virtual ~CMainMenuSubclass();

	void Initialization(CWnd* pMainWnd, CRect rcBound);
	void Finalization();

	BOOL InitMenuItems();
	void DeleteMenuItems();

	void OnPaint(CDC*);
	void OnLButtonDown(int x, int y); //Relative to Window top left
	void OnNcMouseMove(int x, int y); //Relative to Window top left
	void SetBoundRect(CRect rcMenu);
	UINT OnDrawItem(LPDRAWITEMSTRUCT lpDIS);
	UINT OnMeasureItem(LPMEASUREITEMSTRUCT lpMIS);
private:
	CRect m_rcBound;
	CArray<CMenuItem*, CMenuItem*> m_arrMenuItem;
	CWnd* m_pWndMain;
	CMenu* m_pMenuMain;
	int m_nCurrIndex;
	BOOL m_bLoop;
	BOOL m_bSelected;

	friend class CMenuItem;

private:
	void DoGradientFill(CDC *pDC, CRect* rect);
	int PointToIndex(int x, int y);
	void TrackPopup(int nNewIndex);
	static LRESULT CALLBACK MenuInputFilter(int code, WPARAM wParam, LPARAM lParam);
	BOOL OnMenuInput(MSG& m);
	void UpdateMainMenu();
};

#endif // !defined(AFX_MAINMENUSUBCLASS_H__381F2AC3_0C44_4BD3_A0C9_647DDB3980A7__INCLUDED_)
